Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jun 11, 2025

Link issues

fixes #6202

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Enable the PrintButton component to correctly render and print canvas elements by moving them into a temporary print container and restoring the original canvases after printing.

New Features:

  • Support printing of canvas HTML elements in modal print views

Bug Fixes:

Enhancements:

  • Refactor print logic into helper functions for creating print content, managing placeholders, and restoring canvases
  • Temporarily hide the modal during printing and restore its visibility afterward

@bb-auto bb-auto bot added the enhancement New feature or request label Jun 11, 2025
@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 11, 2025
@codecov
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5cdf89a) to head (6ece962).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6203   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          704       704           
  Lines        31100     31100           
  Branches      4394      4394           
=========================================
  Hits         31100     31100           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit a828f38 into main Jun 11, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the fix-print branch June 11, 2025 02:36
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 11, 2025

Reviewer's Guide

Refactored the PrintButton component to modularize print logic, hide the modal during printing, and add full support for rendering and restoring canvas elements by moving them into placeholders before print and back after.

Sequence Diagram for Enhanced Print Process with Canvas Support

sequenceDiagram
    actor User
    participant PrintScript as "PrintButton.razor.js"
    participant DOM
    participant BrowserPrint as "Browser Print Service"

    User->>PrintScript: Clicks PrintButton, triggers print(el)
    PrintScript->>DOM: Hide associated modal
    PrintScript->>PrintScript: Call createPrintContent(modalBody)
    activate PrintScript
    PrintScript->>DOM: Get canvas elements from modalBody
    loop For each canvas in modalBody
        PrintScript->>DOM: Create placeholder for canvas (via createCanvasPlaceholder)
        PrintScript->>DOM: Move canvas to print view (via moveCanvas)
    end
    PrintScript->>DOM: Create printContainer with content & modified canvases
    deactivate PrintScript
    PrintScript->>DOM: Append printContainer to document body
    PrintScript->>BrowserPrint: window.print()
    BrowserPrint-->>User: Show Print Dialog
    User-->>BrowserPrint: Interact with Print Dialog (Confirm/Cancel)
    PrintScript->>PrintScript: Call restoreCanvas(printContainer)
    activate PrintScript
    loop For each canvas in printContainer
        PrintScript->>DOM: Move canvas back to original DOM placeholder (via moveCanvas)
        PrintScript->>DOM: Remove original DOM placeholder
    end
    deactivate PrintScript
    PrintScript->>DOM: Remove printContainer from document body
    PrintScript->>DOM: Show associated modal
Loading

Updated Class Diagram for PrintButton.razor.js Module

classDiagram
    class PrintButtonModule {
        <<JavaScript Module: PrintButton.razor.js>>
        +init(id): void
        +print(el): void
        +createPrintContent(content): HTMLDivElement
        +createCanvasPlaceholder(canvas: HTMLCanvasElement): void
        +moveCanvas(canvas: HTMLCanvasElement, target: HTMLElement): void
        +restoreCanvas(printContentEl: HTMLDivElement): void
        +dispose(id): void
    }
Loading

File-Level Changes

Change Details Files
Modularized print content creation into helper function
  • Extracted inline HTML cloning and input/textarea value assignment into createPrintContent
  • Unified ID generation and value copying for form elements
  • Replaced manual DOM manipulation with dialog.innerHTML assignment
src/BootstrapBlazor/Components/Print/PrintButton.razor.js
Implemented canvas support via placeholders
  • Added createCanvasPlaceholder to mark original canvas positions
  • Moved canvas elements into the print container before printing
  • Restored canvas elements to their placeholders after printing
src/BootstrapBlazor/Components/Print/PrintButton.razor.js
Managed modal visibility during print workflow
  • Applied .d-none class to hide the modal before creating print view
  • Added and removed body .bb-printview-open class around window.print call
  • Restored modal visibility after cleanup
src/BootstrapBlazor/Components/Print/PrintButton.razor.js
Introduced helper functions for DOM operations
  • Created moveCanvas to relocate canvas between placeholders and print container
  • Created restoreCanvas to revert moved canvases post-print
src/BootstrapBlazor/Components/Print/PrintButton.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#6202 Implement printing support for canvas HTML elements.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Print): support cavas html element

2 participants